package us.k5n.k5ncal;

///////////////code below by Cristian////////////////////


import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.util.*;


public class DateFormatPanel extends JPanel {

	  DateFormat fDateFormat = null;
	  boolean fFirstPass = true;
	  int fMsgX = 0, fMsgY = 0;
	  Font fFont = new Font ("Arial", Font.PLAIN, 18);

	  /* Get the DateFormat object with the default time style. */
	  DateFormatPanel () {
	    fDateFormat =
	      DateFormat.getTimeInstance (DateFormat.DEFAULT);
	  } 

	  /* Draw the time string on the panel center. */
	  public void paintComponent (Graphics g) {
	    super.paintComponent (g);

	    // Get current date object
	    Date now = new Date ();

	    // Format the time string.
	    String date_out = fDateFormat.format (now);

	    // Use our choice for the font.
	    g.setFont (fFont);

	    // Do the size and placement calculations only for the
	    // first paint  
       
	      if (fFirstPass) {

	       // Get measures needed to center the message
	      FontMetrics fm = g.getFontMetrics ();

	      // How many pixels wide is the string
	      int msg_width = fm.stringWidth (date_out);

	      // Use the string width to find the starting point
	       
	        fMsgX=getSize().width-msg_width;

	      // How far above the baseline can the font go?
	      int ascent = fm.getMaxAscent ();

	      // How far below the baseline?
	      int descent= fm.getMaxDescent ();

	      // Use the vertical height of this font to find
	      // the vertical starting coordinate
	      fMsgY = getSize ().height/2- descent/2 + ascent/2;
	    }  
	   
	    g.drawString (date_out,fMsgX,fMsgY);
	   
	    fFirstPass = false;
	 
	  } // paintComponent  

}	// class DateFormatPanel

////////////code above by Cristian/////////////////
